<?php

$database_type="mysql";
 $host = "localhost";
 $database = "clcs_flickr";
 $dbuser = "clcs_test";
 $dbpassword = "test23";

function DBconnect()
{
$link = mysql_connect("localhost", "clcs_test", "test23");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
 mysql_select_db("clcs_flickr") or die ("schema not found");
}


function IsValidSession($acc_id,$token)
{
     return true;
}

function Logger($direction,$timestamp,$user_agent,$content_lenght,$body_in,$body_out)
{ DBconnect();
    if($direction==1)
	{
    $sql="INSERT INTO `clcs_flickr`.`logs_incoming`(`id`,`timestamp`,`user_agent`,`content_lenght`,`body`)". 
	" VALUES ( NULL,".$timestamp.",".
	mysql_real_escape_string($user_agent).",".
	$content_lenght.",".
	mysql_real_escape_string($body_in).");";
	}
	else
	{
	$sql="INSERT INTO `clcs_flickr`.`logs_outgoing`(`id`,`timestamp`,`request_body`,`responce_body`)".
	" VALUES ( NULL,".$timestamp.",".mysql_real_escape_string($body_in).",".mysql_real_escape_string($body_out).");";
	}
	
	;
	return ExecuteScalar2($sql);
}


function ExecuteScalar2($SQLString)
    {
    
    $DBquery = mysql_query( $SQLString,$link);
    $res=mysql_fetch_array($DBquery);
    mysql_free_result($DBquery);
		mysql_close($mysql_link);

    return $res[0];

    }

     function ExecuteScalar($SQLString)
    {
            $status ="";


            if ($this->MySQLDB->Connected !=true)
            { $this->MySQLDB->Open(); }

            if ($this->MySQLDB->Connected == true)
            {
                $this->MySQLQuery->SQL=$SQLString;
                $this->MySQLQuery->Prepare();

                     //Reopen the dataset
                     $this->MySQLQuery->Active=true;
                    // $this->MySQLQuery->refresh();

                 if( $this->MySQLQuery->RecordCount> 0)
                {

                  $account_id = $this->MySQLQuery->readDataFieldValue();

                  return  $this->MySQLQuery->RecordCount."</br>";
                          //.$account_id[0][0];
                }
                else
                {
                return  "Null Array";
                }
            }
            else
            {
            return "Unable to establish Newtork connection with DB";
            }
    }


?>
